﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NDF.Jsonable;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;

namespace NDF.Test
{
    [TestClass]
    public class JsonTest
    {
        [TestMethod]
        public void DataTableToJsonTest()
        {
            DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
            DataTable table = new DataTable();
            using (DbConnection conn = factory.CreateConnection())
            {
                conn.ConnectionString = @"server=192.168.0.229\MSSQL2008R2;database=ISIWP;uid=sa;password=pas2word@szcp";
                DbCommand command = conn.CreateCommand();
                command.CommandText = "SELECT * FROM Com_User";
                DbDataAdapter adapter = factory.CreateDataAdapter();
                adapter.SelectCommand = command;
                adapter.Fill(table);
            }
            //Console.WriteLine(table.ToJson());
            Console.WriteLine(DateTime.Now.ToJson());
            Console.WriteLine("123".ToJson());
            Console.WriteLine(new bool().ToJson());
            Console.WriteLine(new List<TreeNode>()
            { 
                new TreeNode { },
                new TreeNode { },
                new TreeNode { }
            }.ToJson());
            Console.WriteLine(table.Rows.Count);
        }
    }
}
